//
//  LWCompanyProfileCtrl.m
//  laowu
//
//  Created by Northwan on 15/5/2.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//  劳务公司

#import "LWCompanyProfileCtrl.h"
#import "CompanyProfileResult.h"
#import "LWCompanyModifyCtrl.h"
#import "SelectImgUtils.h"
#import "RecmdListCtrl.h"

@interface LWCompanyProfileCtrl ()<SelectImgUtilsDelegate>
@property (weak, nonatomic) IBOutlet UILabel *companyProfileLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headImgView;
@property (weak, nonatomic) IBOutlet UILabel *companyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyAddressLabel;
@property (weak, nonatomic) IBOutlet UILabel *managerNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *connectPhoneLabel;
//@property (weak, nonatomic) IBOutlet UILabel *pushEmployeeLabel;
//@property (weak, nonatomic) IBOutlet UILabel *pushEmployeePhoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *employeeDescriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *websiteLabel;
@property (strong, nonatomic) CompanyProfileResult *res;



@end

@implementation LWCompanyProfileCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"个人资料"];
    CALayer *layer=[self.headImgView layer];
    [layer setCornerRadius:self.headImgView.width/2];
    [layer setMasksToBounds:YES];
    [layer setBorderWidth:2];
    [layer setBorderColor:[[UIColor whiteColor] CGColor]];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getData];
}

-(void)getData{
    MBProgressHUD *lodingView =  [DialogUtils showLoadingWithView:self.view];
    [MeDataTool getCompanyProfile:^(CompanyProfileRes *result) {
        [lodingView hide:YES];
        if(result.isSucc){
            [self initData:result];
        }else{
            [DialogUtils showTipsWithView:self.view String:result.msg];
        }
    } failure:^(NSError *error) {
        [lodingView hide:YES];
        [DialogUtils showTipsWithView:self.view String:@"加载失败"];
    }];
    
}
-(void)initData:(CompanyProfileRes*)result{
    
    CompanyProfileResult *res = result.datas;
    self.res = res;
    [_companyProfileLabel setText:res.group_name];
    [_headImgView sd_setImageWithURL:[NSURL URLWithString:res.user_img] placeholderImage:[UIImage imageNamed:@"headavatar"]];
    [_companyNameLabel setText:res.o_org_name];
    [_companyAddressLabel setText:res.o_org_address];
    [_managerNameLabel setText:res.o_principal];
    [_connectPhoneLabel setText:res.o_tel];
    [_employeeDescriptionLabel setText:res.o_des];
    [_websiteLabel setText:res.o_website];
//    NSMutableArray *introducerArr = [NSMutableArray array];
//    NSMutableString *introducerNames = [[NSMutableString alloc]init];
//    NSMutableString *introducerPhones = [[NSMutableString alloc]init];
//    [introducerArr addObjectsFromArray:res.introducer];
//    for (int i = 0; i<introducerArr.count; i++) {
//        ProfileIntroducer* introducer =  introducerArr[i];
//        [introducerNames appendString:[NSString stringWithFormat:@" %@",introducer.p_introducer]];
//        [introducerPhones appendString:[NSString stringWithFormat:@" %@",introducer.p_introducer_phone]];
//    }
//    [_pushEmployeeLabel setText:introducerNames];
//    [_pushEmployeePhoneLabel setText:introducerPhones];
}

- (IBAction)modify:(id)sender {
    LWCompanyModifyCtrl *ctrl = [[LWCompanyModifyCtrl alloc] initWithCompanyProfileResult:self.res];
    [self.navigationController pushViewController:ctrl animated:YES];
}

- (IBAction)modifyHeadImg:(id)sender {
    SelectImgUtils *selectImgUtils = [SelectImgUtils shareInstance];
    [selectImgUtils selectImageWithCtrl:self];
    [selectImgUtils setDelegate:self];
}

-(void)selectImgUtilsUrl:(NSString *)url{
    NSLog(@"url=%@",url);
    MBProgressHUD *hud = [DialogUtils showLoadingWithView:nil];
    [MeDataTool modifyUserImgWithUrl:url success:^(BaseResponse *result) {
        [hud hide:YES];
        if (result.isSucc) {
            [DialogUtils showTipsWithView:nil String:@"修改成功"];
            [self.headImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASE_URL,url]]];
            [UserDefaultsHelper setObject:[NSString stringWithFormat:@"%@%@",BASE_URL,url] forKey:KEY_USER_IMG];
        }else{
            [DialogUtils showTipsWithView:nil String:result.msg];
        }
    } failure:^(NSError *error) {
        [hud hide:YES];
        [DialogUtils showTipsWithView:nil String:@"头像修改失败"];
    }];
    
}

- (IBAction)lookRecomdBtnClick:(id)sender {
    //查看推荐人
    RecmdListCtrl *ctrl = [[RecmdListCtrl alloc] init];
    [self.navigationController pushViewController:ctrl animated:YES];
}


@end
